define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
		//查询任课信息
		httpService.post(app.urls.course_info_selectById,{"id":params.id},function(data){
			if("0000" === data.code){
				$scope.info =  data.data;
				$scope.findGrade();
				$scope.findClass();
				$scope.findCourse();
				$scope.find();
			}else{
				alert(data.msg);
			}
		});
		//查询学年学期
		httpService.post(app.urls.prop_select,{"prop_group":'SCORE',"prop_key":'STU_YEAR'},function(data){
			if("0000" === data.code){
				$scope.academics =  data.data;
			}else{
				alert(data.msg);
			}
		});
		//查询学期
		httpService.post(app.urls.prop_select,{"prop_group":'SCORE',"prop_key":'STU_TERM'},function(data){
			if("0000" === data.code){
				$scope.semesters = data.data;
			}else{
				alert(data.msg);
			}
		});
		//查询主校区和分校区
		httpService.post(app.urls.unit_selectSchoolAndAttach,{},function(data){
			if("0000" === data.code){
				$scope.unitList = data.data;
			}else{
				alert(data.msg);
			}
		});
		//查询年级
		$scope.findGrade = function (){
			httpService.post(app.urls.grade_selectCenterGrade,$scope.info,function(data){
				if("0000" === data.code){
					$scope.gradeList = data.data;
				}else{
					alert(data.msg);
				}
			});
		}
		//获取班级
		$scope.findClass=function(){
			httpService.post(app.urls.class_selectClassName,$scope.info,function(data){
				if("0000" === data.code){
					$scope.classList = data.data;
					$scope.findCourse();
				}else{
					alert(data.msg);
				}
			});
		}
		//查询课程
		$scope.findCourse=function(){
			httpService.post(app.urls.course_selectByflag,$scope.info, function (data) {
				if ("0000" === data.code) {
					$scope.courseList = data.data;
				} else {
					alert(data.msg);
				}
			});
		}
		var init =function(){
			//查询当前学年学期
			httpService.post(app.urls.prop_select,{"prop_group":'SCORE','status':'0'},function(data){
				if("0000" === data.code){
					for(var i=0;i<data.data.length;i++){
						if(data.data[i].prop_key=='STU_YEAR'){
							$scope.form.academic =  data.data[i].prop_pk;
						}
						if(data.data[i].prop_key=='STU_TERM'){
							$scope.form.semester =  data.data[i].prop_pk;
						}
					}
				}else{
					alert(data.msg);
				}
			});
		}
		init();
		//查询教师数据
		$scope.find = function(){
			httpService.postpage(app.urls.teacher_selectToList,$scope.info,function(data){
				if("0000" === data.code){
					$scope.rows = data.data;
					$scope.$apply();
					$('input[name="dataPk"][value="'+$scope.info.fk_user+'"]').prop("checked","checked");
				}else{
					alert(data.msg);
				}
			});
		}

		//按钮点击事件-条件查询
		$scope.select = function(){
			$scope.page.current = 1;
			$scope.find();
		}
		$scope.saveForm = function(){
			if($scope.formCheck()) {
				var values = [];
				$('#' + $scope.controllerName + ' input[name="dataPk"]:checked').each(function () {
					values.push($(this).val());
				});
				if (values.length < 1) {
					eventBusService.publish('modal.alert', {"title": "操作提示", "content": "请选择添任课老师。"});
				} else if (values.length > 1) {
					eventBusService.publish('modal.alert', {"title": "操作提示", "content": "您选择了多个任课老师，请重新选择。"});
				} else {
					$scope.info.updateid = $scope.info.id;
					httpService.post(app.urls.course_info_selectIfExit,$scope.info,function(data){
						if(data.data==0){
							$scope.info.fk_user = values[0];
							httpService.post(app.urls.course_info_update, $scope.info, function (data) {
								if ("0000" === data.code) {
									eventBusService.publish("content.page.reload", data.data);
									eventBusService.publish("modal.page.close", {});
								} else {
									alert(data.msg);
								}
							});
						}else{
							alert("已经添加过该课程信息，无需重复添加");
						}
					});
				}
			}
		}

	}}});